package com.xlh.enums.course;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 步骤类型
 * <p>
 * Created by lx on 2019/1/28.
 */
@Getter
@AllArgsConstructor
public enum StepTypeEnum {

    SINGLE(1, "单步骤实验"),
    MULTIPLE(2, "多步骤实验");

    private Integer code;

    private String message;

    public static StepTypeEnum getByCode(Integer code) {
        if (code == null) return null;
        for (StepTypeEnum stepTypeEnum : StepTypeEnum.values()) {
            if (Objects.equals(stepTypeEnum.getCode(), code)) {
                return stepTypeEnum;
            }
        }
        return null;
    }

    public static StepTypeEnum getByMessage(String message) {
        for (StepTypeEnum stepTypeEnum : StepTypeEnum.values()) {
            if (Objects.equals(stepTypeEnum.getMessage(), message)) {
                return stepTypeEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(Integer code) {
        StepTypeEnum stepTypeEnum = getByCode(code);
        return stepTypeEnum == null ? null : stepTypeEnum.getMessage();
    }

}
